<?php

class CodeSpace_Theme_Controller_Plugin_Theme extends Zend_Controller_Plugin_Abstract
{    
       
    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {

        $themeSettings = new Zend_Config_Ini(APPLICATION_PATH . '/configs/theme.ini', 'settings');
        $themeSettings = $themeSettings->toArray();
        $theme = $themeSettings['default'];
        $themeSettings = $themeSettings['theme'][$theme];

        $layout = Zend_Layout::getMvcInstance();
        if (array_key_exists('layout', $themeSettings)) {
            $layout->setLayout($themeSettings['layout']);
        }
        $layout->setLayoutPath($themeSettings['dir']);
        
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $view = $viewRenderer->view;
        
        $view->addHelperPath("CodeSpace/Theme/View/Helper", "CodeSpace_Theme_View_Helper");
        $view->theme()->setTheme($theme);
    }
    
}

?>